package com.tang.springboot_autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

@Configuration
@EnableConfigurationProperties(RedisProperties.class) //RedisProperties就会被spring识别
@ConditionalOnClass(Jedis.class) //如果有jedis 我们才会去加载这个bean
public class RedisAutoConfiguration {
    /*
    提供jredis的bean
    * */
    @Bean
    @ConditionalOnMissingBean(name = "jedis") //如果没有一个名字叫jedis的bean 我们就提供一个给他
    public Jedis jedis(RedisProperties redisProperties){
        System.out.println("springboot提供");
        return new Jedis(redisProperties.getHost(),redisProperties.getPost());
    }
}
